import 'package:flutter/material.dart';

import '../Utils/color_utils.dart';

class BarItem extends StatefulWidget {
  const BarItem({
    super.key,
    required this.icon,
    required this.onTap,
  });
  final String icon;
  final GestureTapCallback onTap;

  @override
  State<BarItem> createState() => _BarItemState();
}

class _BarItemState extends State<BarItem> {
  bool _hovering = false;
  final Color hoveringColor = YZMColors.color_white_50;
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(5),
      padding: const EdgeInsets.all(5),
      decoration: BoxDecoration(
        color: _hovering ? hoveringColor : YZMColors.transparent,
        borderRadius: BorderRadius.circular(4),
      ),
      child: MouseRegion(
        onEnter: (event) {
          setState(() {
            _hovering = true;
          });
        },
        onExit: (event) {
          setState(() {
            _hovering = false;
          });
        },
        child: GestureDetector(
          onTap: widget.onTap,
          // onPanStart和onDoubleTap设置空点击事件，防止触发背景的拖动和双击放大事件
          onPanStart: (details) {},
          onDoubleTap: (){},
          child: Image.asset(
            widget.icon,
            width: 16,
            height: 16,
          ),
        ),
      ),
    );
  }
}